home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / STDLIB.PAK / EXCEPTIO.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  775b  |  35 lines

  1. #include <iostream.h>
  2. #include <stdexcept>
  3.  
  4. using namespace std;
  5.  
  6. #ifdef RWSTD_NO_EXCEPTIONS
  7. int main ()
  8. {
  9.     cout << "Your compiler doesn't support exceptions!" << endl;
  10.     return 0;
  11. }
  12. #else
  13.  
  14. static void f() { throw runtime_error("a runtime error"); }
  15.  
  16. int main ()
  17. {
  18.     //
  19.     // By wrapping the body of main in a try-catch block we can be
  20.     // assured that we'll catch all exceptions in the exception hierarchy.
  21.     // You can simply catch exception as is done below, or you can catch
  22.     // each of the exceptions in which you have an interest.
  23.     //
  24.     try
  25.     {
  26.         f();
  27.     }
  28.     catch (const exception& e)
  29.     {
  30.         cout << "Got an exception: " << e.what() << endl;
  31.     }
  32.     return 0;
  33. }
  34. #endif /*RWSTD_NO_EXCEPTIONS*/
  35.